//
//  UIImageView+Dowload.m
//  JXSH
//
//  Created by wangcl on 2018/1/11.
//  Copyright © 2018年 李保龙. All rights reserved.
//

#import "UIImageView+Dowload.h"
#import "UIImageView+WebCache.h"
@implementation UIImageView (Dowload)

- (void)downloadImageURL:(NSString *)imageURL completion:(void (^)(UIImage *))completion
{
    [self downloadImageURL:imageURL placeholder:nil completion:completion];
}

- (void)downloadImageURL:(NSString *)imageURL placeholder:(UIImage *)placeholder completion:(void (^)(UIImage *))completion{
    __weak typeof(self) weakself = self;
    [self sd_setImageWithURL:[NSURL URLWithString:imageURL]  placeholderImage:placeholder completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        if (image) {
            CATransition *transition = [CATransition animation];
            transition.type = kCATransitionFade;
            transition.duration = 0.35;
            transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
            [weakself.layer addAnimation:transition forKey:nil];
        }
    }];
    
}

@end
